package friend

import (
	"api/common"
	"api/pb/friend"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateFriendGroupLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateFriendGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateFriendGroupLogic {
	return &CreateFriendGroupLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// CreateFriendGroup 新增好友分组
func (l *CreateFriendGroupLogic) CreateFriendGroup(req *types.FriendGroupInfo) (resp *types.Empty, err error) {
	userID, err := common.GetUserIDFromCtx(l.ctx)
	if err != nil {
		return nil, err
	}

	_, err = l.svcCtx.FriendRPC.AddGroup(l.ctx, &friend.GroupInfo{UserId: userID, Name: req.Name, Sort: req.Sort})
	if err != nil {
		return nil, err
	}
	return &types.Empty{}, nil
}
